/*
package com.itheima.filter;

import com.itheima.Utils.JwtUtils;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;
@Component
@WebFilter(urlPatterns = "/*")
public class LoginFilter implements Filter {
    @Autowired
    private JwtUtils jwttuils;
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //强转
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse res = (HttpServletResponse) servletResponse;
        //获取请求路径
        String requestURI = req.getRequestURI();
        //判断请求是不是登录请求
        if(requestURI.equals("/login")){
            filterChain.doFilter(servletRequest,servletResponse);
            return;
        }
        //获取令牌
        String token = req.getHeader("token");
        //如果不是判断是否有令牌
        if(token==null){
            res.setStatus(401);
            return;
        }
        try {
            //如果有令牌 解析令牌
            Map<String, Object> claims = jwttuils.parseJwt(token);
            filterChain.doFilter(servletRequest,servletResponse);
        } catch (IOException e) {
            res.setStatus(401);
        }
    }
}
*/
